/**
 * 作者: dailc
 * 时间: 2016-05-24
 * 描述: 首页 
 */
define(function(require, exports, module) {
	"use strict";
	//每一个页面都要引入的工具类
	var CommonTools = require('CommonTools_Core');
	//window操作
	var WindowTools = require('WindowTools_Core');
	//UI的初始化
	var UITools = require('UITools_Core');
	var GallerySliderTools = require('GallerySliderTools_Core');
	//每一个页面都要引入的工具类
	// initready 要在所有变量初始化做完毕后
	CommonTools.initReady(initData);
	/**
	 * @description 初始化数据,结合initReady使用
	 * plus情况为plusready
	 * 其它情况为直接初始化
	 */
	function initData(isPlus) {
		//plus下仅支持竖屏显示-设为竖屏,false为横屏
		CommonTools.lockOrientation(true);
		//引入必备文件,下拉刷新依赖于mui
		CommonTools.importFile([
			'js/libs/mui.min.js',
			'js/libs/mui.picker.min.js'
		], function() {
			showDataPicker();
			openAd();
			openUsedcar();
			openDrivingSchool();
			openFindCoach();
			openRecommendCar();
			openApply();
			openOrderStudy();
			openLearnPort();
			me();
			initGallerySlider();
			//plus下双击返回退出-需要Mui
			WindowTools.dbClickExit();
			if(isPlus) {
				WindowTools.preloadTemplate();
				//关闭splash
				plus.navigator.closeSplashscreen();
			}
		});
	}

	/**
	 *@description 日期选择 
	 */
	function showDataPicker() {
		mui('.mui-content').on('tap', '#timepicker', function() {
			console.log("car exe");
			var dtPicker = new mui.DtPicker();
			dtPicker.show(function(selectItems) {
				console.log(selectItems.y); //{text: "2016",value: 2016} 
				console.log(selectItems.m); //{text: "05",value: "05"} 
			})
		});
	}
	
	function openAd(){
		mui('.mui-content').on('tap', '#home_ad', function() {
			console.log("car exe");
			var style = {};
			WindowTools.createWin(null, "./ad/ad_list.html", null, style);
		});
	}
	
	function openUsedcar(){
		mui('.mui-content').on('tap', '#home_usedcar', function() {
			var style = {};
			WindowTools.createWin(null, "./usedcar/car_brand.html", null, style);
		});
	}
	
	function openOrderStudy(){
		mui('.mui-content').on('tap', '#home_order_study', function() {
			var style = {};
			WindowTools.createWin(null, "./school/orderstudy.html", null, style);
		});
	}
	
	function openDrivingSchool(){
		mui('.mui-content').on('tap', '#home_driving_school', function() {
			var style = {};
			WindowTools.createWin(null, "./map/demo_map_baidumapH5.html", null, style);
		});
	}
	
	function openFindCoach(){
		mui('.mui-content').on('tap', '#home_find_coach', function() {
			var style = {};
			WindowTools.createWin(null, "./exam/find_coach.html", null, style);
		});
	}
	
	function openRecommendCar(){
		mui('.mui-content').on('tap', '#home_recommend_car', function() {
			var style = {};
			WindowTools.createWin(null, "./exam/recommend_car.html", null, style);
		});
	}
	
	function openApply(){
		mui('.mui-content').on('tap', '#home_apply', function() {
			var style = {};
			WindowTools.createWin(null, "./exam/apply.html", null, style);
		});
	}
	
	function openLearnPort(){
		mui('.mui-content').on('tap', '#learn_port', function() {
			var style = {};
			WindowTools.createWin(null, "./learnPort/learn_port.html", null, style);
		});
	}
	
	function me(){
		mui(".mui-table-view").on('tap','.mui-table-view-cell',function(){
			var linkUrl = this.getAttribute('link-url');
			var style = {};
			WindowTools.createWin(null,linkUrl, null, style);
		});
	}
	
	/**
	 * @description 初始化图片轮播
	 */
	function initGallerySlider() {
		createGallerySliderDefault();
	}
	
	/**
	 * @description 创建默认图片轮播
	 */
	function createGallerySliderDefault() {
		//默认轮播数据
		var GalleryData = [{
			id: "testgallery1",
			title: "", //为空
			url: "../img/gallery/img_testgallery1.jpg"
		}, {
			id: "testgallery2",
			title: "", //为空
			url: "../img/gallery/img_testgallery2.jpg"
		}, {
			id: "testgallery3",
			title: "", //为空
			url: "../img/gallery/img_testgallery3.jpg"
		}, {
			id: "testgallery4",
			title: "", //为空
			url: "../img/gallery/img_testgallery4.jpg"
		}];
		var options = {
			isLoop: true,
			isAuto: true,
			autoTime: 3000,
			//图片的最大高度,可以不传
			maxImgHeight: '100%',
			//如果是每一个item有多张图,那么决定每一行显示几张图
			perLineItem: 2,
			//是否显示下面的Indicator
			isShowIndicator: true,
			//是否显示下面的翻页Indicator
			isShowPageIndicator: false
		};
		addGallery(GalleryData, options);
	}
	
	/**
	 * @description 添加轮播图片工具方法
	 * @param {JSON} GalleryData
	 * @param {JSON} options 对应参数
	 */
	function addGallery(GalleryData, options) {
		var myGallery = GallerySliderTools.addGalleryLandscape('#gallerySlider', GalleryData, function(e, id) {
			console.log("点击:" + id);
		}, options);
	}

});